/*
*************************************************************************
本文件归属于西安协同时光软件有限公司，未经许可，不得擅自使用、拷贝和修改
*项目组:解决方案部项目开发框架
*版 本: 1.0   
*日 期：Feb 26, 2010   
*时 间：9:42:14 AM   
*作 者：Alex   
*************************************************************************   
*/  
package com.manager.commons.config;  

import java.util.Map;

import org.apache.log4j.Logger;
import org.igfay.jfig.JFig;
import org.igfay.jfig.JFigException;
import org.igfay.jfig.JFigLocator;

/**   
 * TODO 读取配置文件的JFig实现   *   
 * @author  Alex   
 * @since  jdk1.6   */
public class JFigConfig implements Config {
	
	private static final Logger logger = Logger.getLogger(JFigConfig.class);
	
	private static final long serialVersionUID = 1L;
    
	private static final String CONFIG_NAME = "config.xml";
	
	private static final String CONFIG_LOCATION = "classpath";
	
	@Override
	public String getString(String section, String entry) {
		String value = null;
		try 
		{
			value = JFig.getInstance().getValue(section, entry);
		} 
		catch (JFigException ex) 
		{
			return null;
		}
		return value;
	}

	@Override
	public void init() {
		try {
			JFigLocator jFigLocator = new JFigLocator(CONFIG_NAME);
			jFigLocator.setConfigLocation(CONFIG_LOCATION);
			JFig.initialize(jFigLocator);
		}
		catch(Exception e) {
			logger.error("初始化系统配置文件出错");
			e.printStackTrace();
		}
	}
	@Override
	public Map<String,String> getSection(String section) {
		Map<String,String> map = null;
		try 
		{
			map = JFig.getInstance().getSection(section);
		} 
		catch (Exception ex) 
		{
			return null;
		}
		return map;
	}
}
